package com.ssy.lingxi.transaction.controller.mobile;


import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.ResponseCode;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.transaction.api.dto.request.*;
import com.ssy.lingxi.transaction.api.dto.response.InquiryListDetailsResponse;
import com.ssy.lingxi.transaction.api.dto.response.InquiryListProductResponse;
import com.ssy.lingxi.transaction.api.dto.response.InquiryListResponse;
import com.ssy.lingxi.transaction.api.dto.response.QuotationExternalStateEnumResponse;
import com.ssy.lingxi.transaction.service.IInquiryService;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;


/**
 *@menu:  交易能力-商品询价-APP
 * @author wrc
 * @date 2020/8/5
 */
@RestController
@RequestMapping("/transaction/mobile")
public class MobileInquiryController extends BaseController {

    @Resource
    IInquiryService inquiryListService;

    /**
     * 询价报价-商品询价记录
     */
    @GetMapping("/inquiry/add/list")
    public Wrapper<PageData<InquiryListResponse>> inquiryAddList(InquiryListRequest request, HttpServletRequest httpServletRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser(httpServletRequest);
        return inquiryListService.inquiryAddList(request, sysUser);
    }

    /**
     * 商品询价-待新增询价单列表查询
     */
    @GetMapping("/inquiry/list")
    public Wrapper<PageData<InquiryListResponse>> inquiryList(InquiryListRequest request, HttpServletRequest httpServletRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser(httpServletRequest);
        return inquiryListService.inquiryList(request, sysUser);
    }

    /**
     * 商品询价-询价单详情
     */
    @GetMapping("/inquiry/list/details")
    public Wrapper<InquiryListDetailsResponse> inquiryListDetails(InquiryListDetailsRequest request, HttpServletRequest httpServletRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser(httpServletRequest);
        return inquiryListService.inquiryListDetails(request,sysUser);
    }

    /**
     * 商品询价-待新增询价单添加
     */
    @PostMapping("/inquiry/list/add")
    public Wrapper inquiryListAdd(@Valid @RequestBody InquiryListAddRequest request, HttpServletRequest httpServletRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser(httpServletRequest);
        String shopId = httpServletRequest.getHeader("shopId");
        if(StringUtils.isNotEmpty(shopId)){
            request.setShopId(Long.valueOf(shopId));
        }
        //app端添加完直接提交审核
        Wrapper<Long> wrapper = inquiryListService.inquiryListAdd(request, sysUser);
        if(wrapper != null && wrapper.getCode() == ResponseCode.SUCCESS.getCode()){
            Long id = wrapper.getData();
            InquiryListSubmitRequest inquiryListSubmitRequest = new InquiryListSubmitRequest();
            inquiryListSubmitRequest.setId(id);
            inquiryListSubmitRequest.setState(1);
            inquiryListSubmitRequest.setAuditOpinion("");
            inquiryListService.inquiryListSubmit(inquiryListSubmitRequest, sysUser);
        }
        return wrapper;
    }

    /**
     * 商品询价-询价单删除
     */
    @PostMapping("/inquiry/list/delete")
    public Wrapper inquiryListDelete(@Valid @RequestBody InquiryListDetailsRequest request) {
        return inquiryListService.inquiryListDelete(request);
    }

    /**
     * 商品询价-询价单删除
     */
    @PostMapping("/inquiry/list/delete/all")
    public Wrapper inquiryListDeleteAll(@Valid @RequestBody InquiryListDeleteAllRequest request) {
        return inquiryListService.inquiryListDeleteAll(request);
    }

    /**
     * 商品询价-询价单修改
     */
    @PostMapping("/inquiry/list/update")
    public Wrapper inquiryListUpdate(@Valid @RequestBody InquiryListUpdateRequest request, HttpServletRequest httpServletRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser(httpServletRequest);
        String shopId = httpServletRequest.getHeader("shopId");
        if(StringUtils.isNotEmpty(shopId)){
            request.setShopId(Long.valueOf(shopId));
        }
        return inquiryListService.inquiryListUpdate(request, sysUser);
    }

    /**
     * 商品询价-询价商品列表查询
     */
    @GetMapping("/enquiry/product/list")
    public Wrapper<PageData<InquiryListProductResponse>> enquiryProductList(EnquiryProductListRequest request) {
        return inquiryListService.enquiryProductList(request);
    }

    /**
     * 商品询价-询价商品列表查询
     */
    @GetMapping("/enquiry/product/all")
    public Wrapper<List<InquiryListProductResponse>> enquiryProductAll(EnquiryProductListRequest request, HttpServletRequest httpServletRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser(httpServletRequest);
        return inquiryListService.enquiryProductAll(request, sysUser);
    }

    /**
     * 商品询价-提交审核
     */
    @PostMapping("/inquiry/list/submit")
    public Wrapper inquiryListSubmit(@RequestBody InquiryListSubmitRequest request, HttpServletRequest httpServletRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser(httpServletRequest);
        return inquiryListService.inquiryListSubmit(request, sysUser);
    }

    /**
     * 商品询价-批量提交审核
     */
    @PostMapping("/inquiry/list/submit/all")
    public Wrapper inquiryListSubmitAll(@RequestBody InquiryListSubmitAllRequest request, HttpServletRequest httpServletRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser(httpServletRequest);
        return inquiryListService.inquiryListSubmitAll(request, sysUser);
    }

    /**
     * 商品询价-待审核询价单一级列表
     */
    @GetMapping("/inquiry/to/audit/list")
    public Wrapper<PageData<InquiryListResponse>> inquiryToAuditList(InquiryListRequest request, HttpServletRequest httpServletRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser(httpServletRequest);
        return inquiryListService.inquiryToAuditList(request, sysUser);
    }

    /**
     * 商品询价-询价单审核（一级）
     */
    @PostMapping("/inquiry/documents/review")
    public Wrapper inquiryDocumentsReview(@RequestBody InquiryListSubmitRequest request, HttpServletRequest httpServletRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser(httpServletRequest);
        return inquiryListService.inquiryDocumentsReview(request, sysUser);
    }

    /**
     * 商品询价-批量审核询价单审核（一级）
     */
    @PostMapping("/inquiry/documents/review/all")
    public Wrapper inquiryDocumentsReviewAll(@RequestBody InquiryListSubmitAllRequest request, HttpServletRequest httpServletRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser(httpServletRequest);
        return inquiryListService.inquiryDocumentsReviewAll(request, sysUser);
    }

    /**
     * 商品询价-待审核询价单二级列表
     */
    @GetMapping("/inquiry/to/audit/list/two")
    public Wrapper<PageData<InquiryListResponse>> inquiryToAuditListTwo(InquiryListRequest request, HttpServletRequest httpServletRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser(httpServletRequest);
        return inquiryListService.inquiryToAuditListTwo(request, sysUser);
    }

    /**
     * 商品询价-审核询价单（二级）
     */
    @PostMapping("/inquiry/documents/review/two")
    public Wrapper inquiryDocumentsReviewTwo(@RequestBody InquiryListSubmitRequest request, HttpServletRequest httpServletRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser(httpServletRequest);
        return inquiryListService.inquiryDocumentsReviewTwo(request, sysUser);
    }

    /**
     * 商品询价-批量审核询价单（二级）
     */
    @PostMapping("/inquiry/documents/review/all/two")
    public Wrapper inquiryDocumentsReviewAllTwo(@RequestBody InquiryListSubmitAllRequest request, HttpServletRequest httpServletRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser(httpServletRequest);
        return inquiryListService.inquiryDocumentsReviewAllTwo(request, sysUser);
    }

    /**
     * 商品询价-待提交询价单列表
     */
    @GetMapping("/submit/inquiry/sheet/list")
    public Wrapper<PageData<InquiryListResponse>> submitInquirySheetList(InquiryListRequest request, HttpServletRequest httpServletRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser(httpServletRequest);
        return inquiryListService.submitInquirySheetList(request, sysUser);
    }

    /**
     * 商品询价-提交询价单
     */
    @PostMapping("/inquiry/submit")
    public Wrapper inquirySubmit(@RequestBody InquiryListSubmitRequest request, HttpServletRequest httpServletRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser(httpServletRequest);
        return inquiryListService.inquirySubmit(request, sysUser);
    }

    /**
     * 商品询价-批量提交询价单
     */
    @PostMapping("/inquiry/submit/all")
    public Wrapper inquirySubmitAll(@RequestBody InquiryListSubmitAllRequest request, HttpServletRequest httpServletRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser(httpServletRequest);
        return inquiryListService.inquirySubmitAll(request, sysUser);
    }

    /**
     * 商品询价-内部工作流程枚举
     */
    @GetMapping("/product/inquiry/interior/state/enum")
    private Wrapper<List<QuotationExternalStateEnumResponse>> getProductInquiryInteriorEnum(QuotationExternalStateEnumRequest request) {
        return inquiryListService.getProductInquiryInteriorEnum(request);
    }

    /**
     * 商品询价-外部工作流程枚举
     */
    @GetMapping("/product/inquiry/external/state/enum")
    private Wrapper<List<QuotationExternalStateEnumResponse>> getProductexternalInteriorEnum() {
        return inquiryListService.getProductexternalInteriorEnum();
    }

    /**
     * 商品询价-用户积分数据同步处理内部接口
     */
    @PostMapping("/member/inquiry/integral/update")
    private Wrapper memberInquiryIntegralUpdate(@Valid @RequestBody MemberInquiryIntegralUpdateRequest request) {
        return inquiryListService.memberInquiryIntegralUpdate(request);
    }
}
